

#{if showPosition.toString() == 'INDEX_BLOCK'}
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">添加轮播图</h3>
        <div class="panel-options">
            <a href="#" data-toggle="panel">
                <span class="collapse-icon">&ndash;</span>
                <span class="expand-icon">+</span>
            </a>
            <a href="#" data-toggle="remove">
                &times;
            </a>
        </div>
    </div>
    <div class="panel-body">
        <form id="block_form" method="post" role="form" action="/activity/ActivityCtrl/saveBlocks" class="form-horizontal" enctype="multipart/form-data">
            <input type="hidden" id="activityId" name="activity.id" value="">
            <div class="form-group">
                <input type="hidden" id="activity_product_id_1" name="product1.id" value="">
                <label class="col-sm-2 control-label" for="file_1">轮播图1</label>

                <div class="col-sm-10">
                    <input id="file_1" type="file" class="form-control" name="imageFile1">
                    <input id="image_1" type="hidden" class="form-control" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for="file_1">链接地址</label>
                <div class="col-sm-10">
                    <input id="product_url_1" type="text" class="form-control" name="product1.url">
                </div>

            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="file_1"></label>
                <div class="col-sm-10">
                    <img src="" id="block_1" style="width: 100%;"/>
                </div>

            </div>

            <div class="form-group">
                <input type="hidden" id="activity_product_id_2" name="product2.id" value="">

                <label class="col-sm-2 control-label" for="ffile_2">轮播图2</label>

                <div class="col-sm-10">
                    <input id="file_2" type="file" class="form-control" name="imageFile2">
                    <input id="image_2" type="hidden" class="form-control" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for="file_1">链接地址</label>
                <div class="col-sm-10">
                    <input id="product_url_2" type="text" class="form-control" name="product2.url">
                </div>

            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="ffile_2"></label>
                <div class="col-sm-10">
                    <img src="" id="block_2" style="width: 100%;"/>
                </div>
            </div>


            <div class="form-group">
                <input type="hidden" id="activity_product_id_3" name="product3.id" value="">

                <label class="col-sm-2 control-label" for="file_3">轮播图3</label>

                <div class="col-sm-10">
                    <input id="file_3" type="file" class="form-control" name="imageFile3">
                    <input id="image_3" type="hidden" class="form-control" >
                </div>

            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for="file_1">链接地址</label>
                <div class="col-sm-10">
                    <input id="product_url_3" type="text" class="form-control" name="product3.url">
                </div>

            </div>

            <div class="form-group">

                <label class="col-sm-2 control-label" for="file_3"></label>
                <div class="col-sm-10">
                    <img src="" id="block_3" style="width: 100%;"/>
                </div>

            </div>


            <div class="form-group" style="text-align: center;">
                <button type="button" class="btn btn-success" style="width: 120px;">提交</button>
                <button type="reset" class="btn btn-white" style="width: 120px;">重置</button>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    var showPosition = '${showPosition}' ;
    $(function () {
        $.getJSON('/activity/ActivityCtrl/getActivityAndProducts',{showPosition: showPosition} , function (data) {
            var activity = data.activity ;
            var productList = data.productList ;
            console.log(activity)
            if(activity != null){
                $('#activityId').val(activity.id);
            }
            if(productList != null){

                for(var i = 0 ; i < productList.length ; i++){
                    var product = productList[i];
                    var index = i+1 ;
                    console.log(index);
                    console.log(product.imgSrc);

                    $('#image_'+index).val(product.imgSrc);
                    $('#block_'+index).attr('src' , product.imgSrc);
                    $('#activity_product_id_'+index).val(product.id);
                    $('#product_url_'+index).val(product.url);
                }
            }

        })

        $(document).on('click' , '.btn-success' , function () {
            var imageFile1 = $('#file_1').val();
            var imageFile2 = $('#file_2').val();
            var imageFile3 = $('#file_3').val();
            var image1 = $('#image_1').val();
            var image2 = $('#image_2').val();
            var image3 = $('#image_3').val();
            var producturl1 = $('#product_url_1').val();
            var producturl2 = $('#product_url_2').val();
            var producturl3 = $('#product_url_3').val();
            if(checkEmpty(imageFile1) == 1 && checkEmpty(image1) == 1 && checkEmpty(producturl1) == 0 ){
                layer.alert('请为轮播图1 上传图片!',{icon:0 , title:'系统提示'});
                return;
            }
            if(checkEmpty(imageFile2) == 1 && checkEmpty(image2) == 1 && checkEmpty(producturl2) == 0 ){
                layer.alert('请为轮播图2 上传图片!',{icon:0 , title:'系统提示'});
                return;
            }
            if(checkEmpty(imageFile3) == 1 && checkEmpty(image3) == 1 && checkEmpty(producturl3) == 0 ){
                layer.alert('请为轮播图3 上传图片!',{icon:0 , title:'系统提示'});
                return;
            }

//            if(checkEmpty(imageFile1) == 1 && checkEmpty(imageFile2) == 1  && checkEmpty(imageFile3) == 1 ){
//                layer.alert('需上传或者修改的轮播图不能为空!',{icon:0 , title:'系统提示'});
//                return;
//            }
            $('#block_form').submit();

        })
    })

</script>
#{/if}

#{if showPosition.toString() == 'INDEX_NOTICE'}
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">日职头条</h3>
        <div class="panel-options">
            <a href="#" data-toggle="panel">
                <span class="collapse-icon">&ndash;</span>
                <span class="expand-icon">+</span>
            </a>
            <a href="#" data-toggle="remove">
                &times;
            </a>
        </div>
    </div>
    <div class="panel-body">
        <form id="notice_form" role="form" action="/activity/ActivityCtrl/saveNotice" method="post"  class="form-horizontal">
            <div class="form-group">
                <input type="hidden" id="activity_product_id_1" name="product1.id" value="">

                <label class="col-sm-2 control-label" for="field-1">头条一</label>

                <div class="col-sm-10">
                    <input type="text"  name="product1.title" class="form-control" id="notice_1" placeholder="请输入文字内容">
                </div>
            </div>

            <div class="form-group-separator"></div>

            <div class="form-group">
                <input type="hidden" id="activity_product_id_2" name="product2.id" value="">

                <label class="col-sm-2 control-label" for="field-2">头条二</label>

                <div class="col-sm-10">
                    <input type="text" name="product2.title" class="form-control" id="notice_2" placeholder="请输入文字内容">
                </div>
            </div>

            <div class="form-group-separator"></div>

            <div class="form-group">
                <input type="hidden" id="activity_product_id_3" name="product3.id" value="">

                <label class="col-sm-2 control-label">头条三</label>

                <div class="col-sm-10">
                    <input type="text" name="product3.title" class="form-control" id="notice_3" placeholder="请输入文字内容">
                </div>
            </div>
            <div class="form-group" style="text-align: center;">
                <button type="button" class="btn btn-success" style="width: 120px;">提交</button>
                <button type="reset" class="btn btn-white" style="width: 120px;">重置</button>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    var showPosition = '${showPosition}' ;
    $(function () {
        $.getJSON('/activity/ActivityCtrl/getActivityAndProducts', {
            showPosition: showPosition
        }, function (data) {
            var activity = data.activity;
            var productList = data.productList;
            if (activity != null) {
                $('#activityId').val(activity.id);
            }
            if (productList != null) {

                for (var i = 0; i < productList.length; i++) {
                    var product = productList[i];
                    var index = i + 1;
                    console.log(product);

                    $('#notice_' + index).val(product.title);
                    $('#activity_product_id_' + index).val(product.id);
                }
            }

        })

        //保存提交
        $(document).on('click','.btn-success' , function () {
            var notice_1 = $('#notice_1').val();
            var notice_2 = $('#notice_2').val();
            var notice_3 = $('#notice_3').val();


            if(checkEmpty(notice_1) == 1 && checkEmpty(notice_2) == 1 && checkEmpty(notice_3) == 1 ){
                layer.alert("请至少填写一条信息!",{icon:0 , title:'系统提示'});
                return ;
            }

            $('#notice_form').submit();
        })

    });

</script>
#{/if}

#{if showPosition.toString() == 'INDEX_SECKILL'}
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">秒杀</h3>
        <div class="panel-options">
            <a href="#" data-toggle="panel">
                <span class="collapse-icon">&ndash;</span>
                <span class="expand-icon">+</span>
            </a>
            <a href="#" data-toggle="remove">
                &times;
            </a>
        </div>
    </div>
    <div class="panel-body">
        <form id="seckill_form" action="/activity/ActivityCtrl/saveSeckll" method="post" role="form" class="form-horizontal">
            <input type="hidden" id="activityId" name="activity.id" value="">
            <div class="form-group">
                <label class="col-sm-2 control-label">活动开始时间</label>
                <div class="col-sm-4">
                    <div class="date-and-time">
                        <input id="activity_beginAtStr" name="activity.beginAtStr"  type="text"  readonly class="form-control datepicker" data-format="yyyy-mm-dd">
                        <input id="activity_beginTimes" name="activity.beginTimes"   type="text" readonly class="form-control timepicker" data-template="dropdown" data-show-seconds="false" data-default-time="12:00" data-show-meridian="false" data-minute-step="1" />
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">活动结束时间</label>
                <div class="col-sm-4">
                    <div class="date-and-time">
                        <input  id="activity_endAtStr" name="activity.endAtStr"   type="text" readonly class="form-control datepicker" data-format="yyyy-mm-dd">
                        <input  id="activity_endTimes" name="activity.endTimes"   type="text" readonly class="form-control timepicker" data-template="dropdown" data-show-seconds="false" data-default-time="12:00" data-show-meridian="false" data-minute-step="1"/>
                    </div>
                </div>
            </div>

            <div class="form-group-separator"></div>

        </form>
    </div>
</div>



<script type="text/javascript">
    var showPosition = '${showPosition}' ;
    var productIndex = 0 ;

    $(function () {
        $.getJSON('/activity/ActivityCtrl/getActivityAndProducts', {showPosition: showPosition}, function (data) {
            var activity = data.activity;
            var productList = data.productList;

            if (activity != null) {
                $('#activityId').val(activity.id);
                $('#activity_beginAtStr').val(activity.beginAtStr);
                $('#activity_beginTimes').val(activity.beginTimes);
                $('#activity_endAtStr').val(activity.endAtStr);
                $('#activity_endTimes').val(activity.endTimes);

            }
            var str = '';
            if (productList != null) {
                for (var i = 0; i < productList.length; i++) {
                    var product = productList[i];
                    str += ' <div class="form-group">'
                            +' <div id_activity_product_id="'+product.id+'" id_product_id="'+product.product.id+'" id_product_activityPrice="'+product.activityPrice+'" id_product_name="'+product.product.name+'"  class="edit_product">'
                            +' <label class="col-sm-2 control-label">秒杀产品 '+(i+1)+'</label>'
                            +' <div class="col-sm-4">'
                            +'  <input class="form-control edit_product" readonly value="'+product.product.name+'" type="text" placeholder="选择产品">'
                            +'  </div>'
                            +' <label class="col-sm-1 control-label" for="field-1">秒杀价</label>'
                            +' <div class="col-sm-3">'
                            +' <input  readonly  class="form-control " type="number" value="'+product.activityPrice+'" placeholder="0.00">'
                            +' </div> '
                            +' </div> '
                            +'  <div class="col-sm-2">'
                            +' <button id_activity_product_id="'+product.id+'"  type="button" class="btn btn-danger del_product_button" style="width: 120px;">删除</button>'
                            +' </div>'

                            +' </div>';
                }
            }
            str += ' <div class="form-group" style="text-align: center;"> '
                    +'<button type="submit" class="btn btn-success" style="width: 120px;">保存活动</button> '
                    +'<button type="button" class="btn btn-info btn_select_product" style="width: 120px;" >添加产品</button> '
                    +'</div>';

            $('#seckill_form').append(str);

        })

        //选择秒杀产品
        getProducts();


        //保存提交
        $(document).on('click','.btn-success' , function () {

            var beginAtStr = $('#activity_beginAtStr').val();
            var endStr = $('#activity_endAtStr').val();
            var beginTimes = $('#activity_beginTimes').val();
            beginTimes = parseInt(beginTimes)<10 ? ('0'+beginTimes) : beginTimes ;
            var endTimes = $('#activity_endTimes').val();
            endTimes = parseInt(endTimes) <10 ? ('0'+endTimes) : endTimes ;

            var beginDate = beginAtStr+' '+ beginTimes  ;

//            alert('beginAtStr:'+beginAtStr
//                    + '\n endStr:'+endStr
//                    +'\nbeginTimes:'+ beginTimes
//                    + '\n endTimes:'+ endTimes
//                    + '\nbeginDate:'+beginDate);
            if(beginAtStr > endStr) {
                layer.alert("结束日期不能小于开始日期",{icon:0 , title:'系统提示'});
                return false;
            }


            if( beginTimes >= endTimes ){
                layer.alert("活动结束时间不能小于等于开始时间",{icon:0 , title:'系统提示'});
                return false ;
            }

            if(dateComPare(beginDate) == 1 ){
                layer.alert("活动开始时间不能小于等于当前时间",{icon:0 , title:'系统提示'});
                return false ;
            }

            $('#seckill_form').submit();
        })

        $(document).on('click','.btn_select_product' , function () {
            var activityId = $('#activityId').val();

            var beginAtStr = $('#activity_beginAtStr').val() ;
            var beginTimes = $('#activity_beginTimes').val() ;
            var endAtStr = $('#activity_endAtStr').val() ;
            var endTimes = $('#activity_endTimes').val() ;
            if(checkEmpty(activityId) == 1  ){
                layer.alert("请先保存秒杀活动!",{icon:0 , title:'系统提示'});
                return ;
            }

            if(checkEmpty(beginAtStr) == 1 || checkEmpty(beginTimes) == 1  || checkEmpty(endAtStr) == 1 || checkEmpty(endTimes) == 1  ){
                layer.alert("请设置活动时间!",{icon:0 , title:'系统提示'});
                return ;
            }


            $('#id_activity_id').val(activityId); // 秒杀活动的ID
            $('#id_activity_product_id').val('');// 秒杀活动关联的活动产品ID
            $('#id_product_id').val(''); // 活动产品关联的产品ID
            $('#id_product_name').val(''); // 活动产品关联的产品名称
            $('#id_product_activityPrice').val(''); // 活动 产品 秒杀价格
//
            $('#id_kill_product').modal('show');
        })

        // 点击编辑秒杀产品 信息
        $(document).on('click' , '.edit_product' , function () {
            var activityId = $('#activityId').val();
            var id_activity_product_id = $(this).attr('id_activity_product_id');
            var id_product_id = $(this).attr('id_product_id');
            var id_product_name = $(this).attr('id_product_name');
            var id_product_activityPrice = $(this).attr('id_product_activityPrice');

            $('#id_activity_id').val(activityId); // 秒杀活动的ID
            $('#id_activity_product_id').val(id_activity_product_id);// 秒杀活动关联的活动产品ID
            $('#id_product_id').val(id_product_id); // 活动产品关联的产品ID
            $('#id_product_name').val(id_product_name); // 活动产品关联的产品名称
            $('#id_product_activityPrice').val(id_product_activityPrice); // 活动 产品 秒杀价格

            $('#id_kill_product').modal('show');
        })

        //删除秒杀产品
        $(document).on('click' , '.del_product_button' , function () {
            var activityProductId = $(this).attr('id_activity_product_id') ;

            layer.confirm('确认删除?', {icon: 3, title:'提示'}, function(index){

                $.getJSON('/activity/ActivityCtrl/deletedSeckillProduct',{activityProductId:activityProductId} , function (data) {
                    window.location.href = '/activity/ActivityCtrl/index?showPosition=INDEX_SECKILL' ;
                });

                layer.close(index);
            });


        })

    });

    //保存秒杀产品
    function saveKillProduct() {
        var activityId = $('#activityId').val();
        if(checkEmpty(activityId)==1){
            layer.alert("请先保存秒杀活动!",{icon:0 , title:'系统提示'});
            return ;
        }
        $('#editKillProductForm').submit();
    }

    function callBack(id , name , price) {
        $('#id_product_id').val(id);
        $('#id_product_name').val(name);
        $('#id_product_activityPrice').val(price);
        layer.closeAll();

    }
</script>
#{/if}

#{if  showPosition.toString() == 'INDEX_PROMOTION'}
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">活动图片</h3>
        <div class="panel-options">
            <a href="#" data-toggle="panel">
                <span class="collapse-icon">&ndash;</span>
                <span class="expand-icon">+</span>
            </a>
            <a href="#" data-toggle="remove">
                &times;
            </a>
        </div>
    </div>
    <div class="panel-body">
        <form id="promotion_form" method="post" role="form" action="/activity/ActivityCtrl/savePromotion" class="form-horizontal" enctype="multipart/form-data" >
            <input type="hidden" id="activityId" name="activity.id" value="">
            <div class="form-group">
                <label class="col-sm-2 control-label" for="field-2">图片链接</label>
                <div class="col-sm-10">
                    <input id="url"  name="url" type="text" class="form-control" placeholder="图片链接1" >
                </div>

            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_1" name="product1.id" value="">
                <label class="col-sm-2 control-label" for="file_1">活动图片</label>

                <div class="col-sm-10">
                    <input id="image_file"  type="file" class="form-control" name="imageFile">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="file_1"></label>
                <div class="col-sm-10">
                    <img src="" id="main_image" style="width: 100%;"/>
                </div>

            </div>

            <div class="form-group" style="text-align: center;">
                <button type="button" class="btn btn-success" style="width: 120px;">提交</button>
                <button type="button" class="btn btn-danger deleted_activity" style="width: 120px;">删除</button>
            </div>
        </form>

    </div>
</div>

<script type="text/javascript">
    var showPosition = '${showPosition}' ;
    $(function () {

        //删除活动
        $(document).on('click','.deleted_activity',function () {
            var activityId = $('#activityId').val();
            if(activityId == null || activityId == '' || activityId <= 0){
                layer.msg('活动不存在,删除失败!')
                return ;
            }
            layer.confirm('确认删除?', {icon: 3, title:'提示'}, function(index){

                $.getJSON('/activity/ActivityCtrl/deletedRecomend',{activityId:activityId} , function (data) {
                    window.location.href = '/activity/ActivityCtrl/index' ;
                });

                layer.close(index);
            });

        });

        $.getJSON('/activity/ActivityCtrl/getActivityAndProducts', {showPosition: showPosition}, function (data) {
            var activity = data.activity;
            if (activity != null) {
                console.log(activity)
                $('#activityId').val(activity.id);
                $('#url').val(activity.url);
                $('#main_image').attr('src', activity.mainImg);
            }


            $(document).on('click', '.btn-success', function () {
                var mainImg = $('#image_file').val();

                if (checkEmpty(mainImg) == 1) {
                    layer.alert('请上传图片!', {icon: 0, title: '系统提示'});
                    return;
                }
                $('#promotion_form').submit();

            })
        })
    })
</script>
#{/if}


#{if showPosition.toString() == 'INDEX_PRODUCT_RECOMMEND'}
<link href="http://cdn.bootcss.com/jqueryui/1.12.0/jquery-ui.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/public/css/htmleaf-demo.css">
<link href="/public/css/demo.css" rel="stylesheet" />
<link href="/public/css/evol-colorpicker.min.css" rel="stylesheet" />
<script src="http://cdn.bootcss.com/jqueryui/1.12.0/jquery-ui.min.js"></script>
<script src="/public/jquery/evol-colorpicker.min.js"></script>
<script>

    $(document).ready(function() {
        $("#activity_titleColour").colorpicker();
        $("#activity_subtitleColour").colorpicker();
//        $('#activity_titleColour').colorpicker({
//            color:'#000000'
//        })
//
//        $('#activity_subtitleColour').colorpicker({
//            color:'#000000'
//        })

    });

</script>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">促销</h3>
        <div class="panel-options">
            <a href="#" data-toggle="panel">
                <span class="collapse-icon">&ndash;</span>
                <span class="expand-icon">+</span>
            </a>
            <a href="#" data-toggle="remove">
                &times;
            </a>
        </div>
    </div>
    <div class="panel-body">
        <form id="recomend_form" method="post" role="form" action="/activity/ActivityCtrl/saveRecomend" class="form-horizontal" enctype="multipart/form-data" >
            <input type="hidden" id="activityId" name="activity.id" value="">
            <div class="form-group">
                <label class="col-sm-2 control-label" for="field-1">主标题</label>
                <div class="col-sm-6">
                    <input id="activity_title" name="activity.title" type="text" class="form-control" placeholder="请输入标题名称">
                </div>

                <div class="col-md-4">
                    <input id="activity_titleColour" readonly  name="activity.titleColour"  type="hidden"  placeholder="主标题颜色" />
                </div>

            </div>


            <div class="form-group">
                <label class="col-sm-2 control-label" for="field-2">副标题</label>
                <div class="col-sm-6">
                    <input id="activity_subtitle" name="activity.subtitle"  type="text" class="form-control" placeholder="请输入标题说明">
                </div>
                <div class="col-md-4">
                    <input id="activity_subtitleColour" readonly  name="activity.subtitleColour"  type="hidden" placeholder="副标题颜色" />
                </div>
            </div>

            *{<div class="form-group">}*
                *{<label class="col-sm-2 control-label" for="field-2">图片链接</label>}*
               *{<div class="col-sm-10">}*
                   *{<input id="activity_url"  name="activity.url" type="text" class="form-control" placeholder="图片链接" >}*
               *{</div>}*

            *{</div>}*

            <div class="form-group">
                <label class="col-sm-2 control-label" for="field-4">标题背景图</label>

                <div class="col-sm-10">
                    <input  id="activity_mainImage" name="imageFile"  type="file" class="form-control" >
                </div>

            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for="field-4"></label>
                <div class="col-sm-10">
                    <img src="" id="main_image" style="width: 100%;"/>
                </div>

            </div>

            <div class="form-group-separator"></div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="field-4"></label>

                <div class="col-sm-10">
                    产品选择（6款产品）
                    <!--<input type="file" class="form-control" id="field-4">-->
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_1" name="product1.id" value="">
                <label class="col-sm-2 control-label">产品一</label>
                <div class="col-sm-8">
                    <input id="id_product_id_1" name="product1.product.id" type="hidden">
                    <input id="id_product_name_1" select-product="1" class="form-control select-product" readonly type="text" placeholder="选择业务">
                </div>
                <div class="col-sm-1">
                 <button   type="button"  onclick='delProdct("id_product_name_1")' class="btn btn-danger del_product_button" style="width: 120px;">删除</button>
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_2" name="product2.id" value="">
                <label class="col-sm-2 control-label">产品二</label>
                <div class="col-sm-8">
                    <input id="id_product_id_2" name="product2.product.id" type="hidden">
                    <input id="id_product_name_2" select-product="2" class="form-control select-product" readonly type="text" placeholder="选择业务">
                </div>
                <div class="col-sm-1">
                    <button   type="button"  onclick='delProdct("id_product_id_2")' class="btn btn-danger del_product_button" style="width: 120px;">删除</button>
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_3" name="product3.id" value="">
                <label class="col-sm-2 control-label">产品三</label>
                <div class="col-sm-8">
                    <input id="id_product_id_3" name="product3.product.id" type="hidden">
                    <input id="id_product_name_3" select-product="3" class="form-control select-product" readonly type="text" placeholder="选择业务">
                </div>
                <div class="col-sm-1">
                    <button   type="button"  onclick='delProdct("id_product_id_3")' class="btn btn-danger del_product_button" style="width: 120px;">删除</button>
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_4" name="product4.id" value="">
                <label class="col-sm-2 control-label">产品四</label>
                <div class="col-sm-8">
                    <input id="id_product_id_4" name="product4.product.id" type="hidden">
                    <input id="id_product_name_4" select-product="4" class="form-control select-product" readonly type="text" placeholder="选择业务">
                </div>
                <div class="col-sm-1">
                    <button   type="button"  onclick='delProdct("id_product_id_4")' class="btn btn-danger del_product_button" style="width: 120px;">删除</button>
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_5" name="product5.id" value="">
                <label class="col-sm-2 control-label">产品五</label>
                <div class="col-sm-8">
                    <input id="id_product_id_5" name="product5.product.id" type="hidden">
                    <input id="id_product_name_5" select-product="5" class="form-control select-product" readonly type="text" placeholder="选择业务">
                </div>
                <div class="col-sm-1">
                    <button   type="button"  onclick='delProdct("id_product_id_5")' class="btn btn-danger del_product_button" style="width: 120px;">删除</button>
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_6" name="product6.id" value="">
                <label class="col-sm-2 control-label">产品六</label>
                <div class="col-sm-8">
                    <input id="id_product_id_6" name="product6.product.id" type="hidden">
                    <input id="id_product_name_6" select-product="6" class="form-control select-product" readonly type="text" placeholder="选择业务">
                </div>
                <div class="col-sm-1">
                    <button   type="button"  onclick='delProdct("id_product_id_6")' class="btn btn-danger del_product_button" style="width: 120px;">删除</button>
                </div>
            </div>


            <div class="form-group" style="text-align: center;">
                <button type="submit" class="btn btn-success" style="width: 120px;">提交</button>
                <button type="reset" class="btn btn-white" style="width: 120px;">重置</button>
                <button type="button" class="btn btn-danger deleted_activity" style="width: 120px;">删除本活动</button>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    $("#activity_titleColour").colorpicker();
    $("#activity_subtitleColour").colorpicker();
    // Instanciate colorpickers


    var showPosition = '${showPosition}' ;
    var activityId = '${activityId}' ;
    var productIndex ;
    $(function () {
        //删除活动
        $(document).on('click','.deleted_activity',function () {
            var activityId = $('#activityId').val();
            if(activityId == null || activityId == '' || activityId <= 0){
                layer.msg('活动不存在,删除失败!')
                return ;
            }
            layer.confirm('确认删除?', {icon: 3, title:'提示'}, function(index){
                $.getJSON('/activity/ActivityCtrl/deletedRecomend',{activityId:activityId} , function (data) {
                    window.location.href = '/activity/ActivityCtrl/index' ;
                });

                layer.close(index);
            });

        });


        $.getJSON('/activity/ActivityCtrl/getRecomendActivity',{activityId:activityId} , function (data) {
            var activity = data.activity;
            var productList = data.productList;

            if (activity != null) {
                $('#activityId').val(activity.id);
                $('#activity_title').val(activity.title);
                $('#activity_subtitle').val(activity.subtitle);
                console.log("activity.titleColour",activity.titleColour)
                if(activity.titleColour != null  && activity.titleColour !=  undefined){
                    $('#activity_titleColour').colorpicker({
                        color:activity.titleColour
                    })
                    $('#activity_titleColour').val(activity.titleColour);
                    $('#activity_subtitleColour').val(activity.subtitleColour);
                }
                if(activity.subtitleColour != null && activity.subtitleColour !=  undefined ){
                    $('#activity_subtitleColour').colorpicker({
                        color:activity.subtitleColour
                    })
                }
                $('#main_image').attr('src' ,activity.mainImg);
            }
            if (productList != null) {

                for (var i = 0; i < productList.length; i++) {
                    var product = productList[i];
                    var index = i + 1;
                    console.log("product.product.id=="+product.product.id+"    product.product.name = "+product.product.name);

                    $('#id_product_id_' + index).val(product.product.id);
                    $('#id_product_name_' + index).val(product.product.name);
                    $('#activity_product_id_' + index).val(product.id);
                }
            }

        });


        //选择产品
        getProducts();


        $(document).on('click' , '.btn-success' , function () {
            var product1 = $('#id_product_id_1').val();
            var product2 = $('#id_product_id_2').val();
            var product3 = $('#id_product_id_3').val();
            var product4 = $('#id_product_id_4').val();
            var product5 = $('#id_product_id_5').val();
            var product6 = $('#id_product_id_6').val();

            if(checkEmpty(product1) == 1 && checkEmpty(product2) == 1 && checkEmpty(product3) == 1 && checkEmpty(product4) == 1 && checkEmpty(product5) == 1 && checkEmpty(product6) == 1 ){
                layer.alert('至少选择一款产品!',{icon:0 , title:'系统提示'});
                return false;
            }

            $('#recomend_form').submit();

        })
    })


    function callBack(id , name , price) {
        $('#id_product_id_'+productIndex).val(id);
        $('#id_product_name_'+productIndex).val(name);
        layer.closeAll();

    }

    function delProdct(product){
        console.log(product);
        if(product == 'id_product_name_1'){
            $('#id_product_name_1').val("");
            $('#id_product_id_1').val("");
        }else if(product == 'id_product_id_2'){
            $('#id_product_name_2').val("");
            $('#id_product_id_2').val("");
        }else if(product == 'id_product_id_3'){
            $('#id_product_name_3').val("");
            $('#id_product_id_3').val("");
        }else if(product == 'id_product_id_4'){
            $('#id_product_name_4').val("");
            $('#id_product_id_4').val("");
        }else if(product == 'id_product_id_5'){
            $('#id_product_name_5').val("");
            $('#id_product_id_5').val("");
        }else if(product == 'id_product_id_6'){
            $('#id_product_name_6').val("");
            $('#id_product_id_6').val("");
        }
    }

</script>
#{/if}

#{if showPosition.toString() == 'MERCHANT_RECOMMEND'}
<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">推荐商户</h3>
        <div class="panel-options">
            <a href="#" data-toggle="panel">
                <span class="collapse-icon">&ndash;</span>
                <span class="expand-icon">+</span>
            </a>
            <a href="#" data-toggle="remove">
                &times;
            </a>
        </div>
    </div>
    <div class="panel-body">
        <form id="recomend_merchant_form" method="post" role="form" action="/activity/ActivityCtrl/saveRecommendMerchants" class="form-horizontal" enctype="multipart/form-data" >
            <input type="hidden" id="activityId" name="activity.id" value="">

            <div class="form-group">
                <label class="col-sm-2 control-label" for="field-4"></label>

                <div class="col-sm-10">
                    商户选择（最多6家商户）
                    <!--<input type="file" class="form-control" id="field-4">-->
                </div>
            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_1" name="product1.id" value="">
                <input type="hidden" id="activity_product_deleted_1" name="product1.deleted" value="">

                <label class="col-sm-2 control-label">商户一</label>
                <div class="col-sm-8">
                    <input id="id_merchant_id_1" name="product1.merchant.id" type="hidden">
                    <input id="id_merchant_name_1" select-merchant="1" class="form-control select-merchant" readonly type="text" placeholder="选择商户">
                </div>
                <div class="col-sm-2">
                    <button type="button" delete-button="1" class="btn btn-danger delete-button" style="width: 120px;">删除</button>
                </div>

            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_2" name="product2.id" value="">
                <input type="hidden" id="activity_product_deleted_2" name="product2.deleted" value="">

                <label class="col-sm-2 control-label">商户二</label>
                <div class="col-sm-8">
                    <input id="id_merchant_id_2" name="product2.merchant.id" type="hidden">
                    <input id="id_merchant_name_2" select-merchant="2" class="form-control select-merchant" readonly type="text" placeholder="选择商户">
                </div>
                <div class="col-sm-2">
                    <button type="button"  delete-button="2" class="btn btn-danger delete-button" style="width: 120px;">删除</button>
                </div>

            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_3" name="product3.id" value="">
                <input type="hidden" id="activity_product_deleted_3" name="product3.deleted" value="">

                <label class="col-sm-2 control-label">商户三</label>
                <div class="col-sm-8">
                    <input id="id_merchant_id_3" name="product3.merchant.id" type="hidden">
                    <input id="id_merchant_name_3" select-merchant="3" class="form-control select-merchant" readonly type="text" placeholder="选择商户">
                </div>
                <div class="col-sm-2">
                    <button type="button" delete-button="3" class="btn btn-danger delete-button" style="width: 120px;">删除</button>
                </div>

            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_4" name="product4.id" value="">
                <input type="hidden" id="activity_product_deleted_4" name="product4.deleted" value="">

                <label class="col-sm-2 control-label">商户四</label>
                <div class="col-sm-8">
                    <input id="id_merchant_id_4" name="product4.merchant.id" type="hidden">
                    <input id="id_merchant_name_4" select-merchant="4" class="form-control select-merchant" readonly type="text" placeholder="选择商户">
                </div>
                <div class="col-sm-2">
                    <button type="button" delete-button="4" class="btn btn-danger delete-button" style="width: 120px;">删除</button>
                </div>

            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_5" name="product5.id" value="">
                <input type="hidden" id="activity_product_deleted_5" name="product5.deleted" value="">

                <label class="col-sm-2 control-label">商户五</label>
                <div class="col-sm-8">
                    <input id="id_merchant_id_5" name="product5.merchant.id" type="hidden">
                    <input id="id_merchant_name_5" select-merchant="5" class="form-control select-merchant" readonly type="text" placeholder="选择商户">
                </div>
                <div class="col-sm-2">
                    <button type="button" delete-button="5" class="btn btn-danger delete-button" style="width: 120px;">删除</button>
                </div>

            </div>
            <div class="form-group">
                <input type="hidden" id="activity_product_id_6" name="product6.id" value="">
                <input type="hidden" id="activity_product_deleted_6" name="product6.deleted" value="">
                <label class="col-sm-2 control-label">商户六</label>
                <div class="col-sm-8">
                    <input id="id_merchant_id_6" name="product6.merchant.id" type="hidden">
                    <input id="id_merchant_name_6" select-merchant="6" class="form-control select-merchant" readonly type="text" placeholder="选择商户">

                </div>
                <div class="col-sm-2">
                    <button type="button" delete-button="6" class="btn btn-danger delete-button" style="width: 120px;">删除</button>
                </div>

            </div>


            <div class="form-group" style="text-align: center;">
                <button type="submit" class="btn btn-success" style="width: 120px;">提交</button>
                <button type="reset" class="btn btn-white" style="width: 120px;">重置</button>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    var showPosition = '${showPosition}' ;
    var activityId = '${activityId}' ;
    var productIndex ;
    $(function () {
        $.getJSON('/activity/ActivityCtrl/getActivityAndProducts',{showPosition:showPosition} , function (data) {
            var activity = data.activity;
            var productList = data.productList;

            if (activity != null) {
                $('#activityId').val(activity.id);
            }
            if (productList != null) {

                for (var i = 0; i < productList.length; i++) {
                    var product = productList[i];
                    var index = i + 1;
                    console.log("product==="+product.merchant.name);

                    $('#id_merchant_id_' + index).val(product.merchant.id);

                    $('#id_merchant_name_' + index).val(product.merchant.name);
                    $('#activity_product_deleted_' + index).val(product.deleted);
                    $('#activity_product_id_' + index).val(product.id);
                }
            }

        });

        getMerchants();

        //删除
        $(document).on('click','.delete-button' , function () {
            var delete_idex = $(this).attr('delete-button');
            $('#activity_product_deleted_'+delete_idex).val('DELETED');
            $('#id_merchant_name_'+delete_idex).val(null);

        })


        //保存
        $(document).on('click' , '.btn-success' , function () {
            var product1 = $('#id_merchant_id_1').val();
            var product2 = $('#id_merchant_id_2').val();
            var product3 = $('#id_merchant_id_3').val();
            var product4 = $('#id_merchant_id_4').val();
            var product5 = $('#id_merchant_id_5').val();
            var product6 = $('#id_merchant_id_6').val();

            if(checkEmpty(product1) == 1 && checkEmpty(product2) == 1 && checkEmpty(product3) == 1 && checkEmpty(product4) == 1 && checkEmpty(product5) == 1 && checkEmpty(product6) == 1 ){
                layer.alert('请至少选择一家商户!',{icon:0 , title:'系统提示'});
                return ;
            }

            $('#recomend_merchant_form').submit();

        })
    })


    function callBack(id , name ) {
        $('#id_merchant_id_'+productIndex).val(id);
        $('#id_merchant_name_'+productIndex).val(name);
        layer.closeAll();

    }
</script>
#{/if}


<script type="text/javascript">
    function checkEmpty(val) {
        if(val == null || val == '' || val == undefined)
            return 1;
        return 0 ;

    }
    //时间对比
    function dateComPare(compareDate) {
        var nowTime = new Date();
        var year = nowTime.getFullYear();
        var month = nowTime.getMonth()+1;
        var date = nowTime.getDate();
        var hours = nowTime.getHours();
        var minutes = nowTime.getMinutes();

        if(month <10){
            month = '0'+month;
        }
        if(date <10){

            date = '0' + date;
        }

        if(hours <10){
            hours = '0' + hours;
        }

        if(minutes < 10){
            minutes = '0' + minutes ;
        }

        var nowTimes = year + '-' + month + '-' + date + ' ' + hours + ':' + minutes;
//        alert('year:'+year
//                + '\nmonth :'+month
//                + '\n date :'+date
//                +'\n hours: '+ hours
//                + '\n minutes :'+ minutes
//                + "\nnowTimes: "+nowTimes
//                + '\n compareDate:'+compareDate);
        if (compareDate <= nowTimes)
            return 1;
        return 0;

    }

    //产品弹出框
    function getProducts() {
        //选择产品
        $(document).on('click','.select-product' ,function () {
            productIndex = $(this).attr('select-product');

            layer.open({
                title:"产品选择",
                type: 2,
                area: ['800px', '600px'],
                fixed: true,
                maxmin: false,
                content: '/admin/product/popProduct'
            });
        })
    }

    //商户弹出框
    function getMerchants() {
        //选择商户
        $(document).on('click','.select-merchant' ,function () {
            productIndex = $(this).attr('select-merchant');

            layer.open({
                title:"商户选择",
                type: 2,
                area: ['500px', '600px'],
                fixed: true,
                maxmin: false,
                content: '/admin/merchant/popMerchant'
            });
        })
    }


</script>
